//  this library.
import 'package:flutter/material.dart';
import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart';
import 'package:hktk_app/util/font_util.dart';
import 'package:hktk_app/util/sz_util.dart';
import 'package:hktk_app/widget/question/image_view_widget.dart';

/// 试题显示富文本组件
class StemRichTextWidget extends StatelessWidget {
  /// 富文本字符串
  final String text;

  /// 字体显示
  final TextStyle? textStyle;

  const StemRichTextWidget({
    super.key,
    required this.text,
    this.textStyle,
  });

  @override
  Widget build(BuildContext context) {

    String text1 = text.replaceAll("<table", "<table border='1'");
    return HtmlWidget(
      text1,
      textStyle: textStyle ??
          FontUtil.fontBlack1(
            szUtilComm.szInfo.getZtdxPx()!,
            // 24,
            szYjms: szUtilComm.szInfo.yjms,
          ),
      customWidgetBuilder: (element) {
        if (element.localName == "img") {
          var src = element.attributes["src"];
          return ImageViewWidget(src: src!);
        }
        return null;
      },
    );
  }
}
